<template>
	<view class="transform">
		<view class="business" v-show="!sms_check">
			<view class="inputlist">
				<view class="left">
					<text>银行卡类型</text>
				</view>
				<view class="right">
					<picker mode="selector" :range="card_type_name" @change="choose_card">
						<view>{{card_name}}</view>
					</picker>
				</view>
			</view>
			<view class="inputlist">
				<view class="left">
					<text>银行卡号</text>
				</view>
				<view class="right">
					<input type="number" maxlength="20" placeholder="请输入银行卡卡号" v-model="card_id"
						placeholder-class="inputColor">
				</view>
			</view>
			<view class="inputlist">
				<view class="left">
					<text>预留手机号</text>
				</view>
				<view class="right">
					<input type="number" placeholder="请输入银行卡预留手机号" v-model="tel_no" maxlength="11"
						placeholder-class="inputColor">
				</view>
			</view>
			<view class="inputlist" v-show="card_type == 2">
				<view class="left">
					<text>信用卡验证码</text>
				</view>
				<view class="right">
					<input type="text" placeholder="请输入信用卡验证码" maxlength="18" v-model="vip_code"
						placeholder-class="inputColor">
				</view>
			</view>
			<view class="inputlist" v-show="card_type == 2">
				<view class="left">
					<text>信用卡有效期</text>
				</view>
				<view class="right">
					<input type="text" placeholder="请输入信用卡有效期" maxlength="18" v-model="expiration"
						placeholder-class="inputColor">
				</view>
			</view>
			<view class="btn">
				<button class="btn_sumbit" @click="bindcard" :loading="loading" :disabled="loading">下一步</button>
			</view>

		</view>
		<view class="business" v-show="sms_check">
			<view class="inputlist">
				<view class="left">
					<text>验证码</text>
				</view>
				<view class="right">
					<input type="text" placeholder="请输入验证码" maxlength="6" v-model="sms_code"
						placeholder-class="inputColor">
				</view>
			</view>
			<view class="btn">
				<button class="btn_sumbit" @click="bindconfirm" :loading="loading" :disabled="loading">绑定</button>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		FastBind,
		BindConfirm
	} from "@/api/fast.js"
	export default {
		data() {
			return {
				card_type_name: ['储蓄卡', '信用卡'],
				card_type_arr: [1, 2],
				card_name: '请选择银行卡类型',
				card_type: '',
				card_id: '',
				tel_no: '',
				vip_code: '',
				expiration: '',
				value: '',
				loading: false,
				sms_code: '',
				sms_check: false,
				apply_id: '' //绑卡申请id
			}
		},
		onLoad() {

		},
		onShow() {

		},
		methods: {
			choose_card(e) {
				this.card_name = this.card_type_name[e.detail.value]
				this.card_type = this.card_type_arr[e.detail.value]
			},
			bindcard() {
				if (this.loading) {
					return false
				}
				if (this.card_type == '') {
					uni.showToast({
						title: '请选择银行卡类型',
						icon: 'none'
					})
					return false
				}
				if (this.tel_no == '' || this.card_id == '') {
					uni.showToast({
						title: '请填写完整信息',
						icon: 'none'
					})
					return false
				}
				if (this.card_type == 2) {
					if (this.vip_code == '' || this.expiration == '') {
						uni.showToast({
							title: '请填写信用卡验证码和有效期',
							icon: 'none'
						})
						return false
					}
				}
				this.loading = true
				FastBind({
					card_type: this.card_type,
					tel_no: this.tel_no,
					card_id: this.card_id,
					vip_code: this.vip_code,
					expiration: this.expiration,
				}).then(res => {
					if (res.status == 1) {
						this.apply_id = res.data
						this.sms_check = true
						this.loading = false
					} else {
						this.loading = false
						uni.showToast({
							title: res.message,
							icon: 'none'
						})
					}
				})
			},
			bindconfirm() {
				if (this.sms_code == '') {
					uni.showToast({
						title: '请输入短信验证码',
						icon: 'none'
					})
					return false
				}
				BindConfirm({
					apply_id: this.apply_id,
					sms_code: this.sms_code
				}).then(res => {
					uni.showToast({
						title: res.message,
						icon: 'none'
					})

					if (res.status == 1) {
						setTimeout(() => {
							uni.navigateBack()
						})
					} else {
						this.loading = false

					}
				})
			}
		}
	}
</script>

<style lang="scss">
	page {
		background: #F3F3F3;
		position: relative;
	}

	.passwordbox {
		position: fixed;
		width: 100%;
		left: 0;
		height: 100vh;
		background: #0000003b;
		top: 0;
		z-index: 9;

		.passwordmain {
			position: fixed;
			z-index: 999;
			background: #fff;
			width: 94%;
			left: 3%;
			padding: 40px 10px;
			box-sizing: border-box;
			border-radius: 8px;
			top: 25%;

			.password_title {
				font-size: 14px;
				font-weight: bold;
				border-bottom: 1px solid #ccc;
				padding-bottom: 8px;
			}

			input {
				margin-top: 10px;
				font-size: 14px;
				padding: 10px;
			}

			.btns {
				display: flex;
				justify-content: space-around;
				margin-top: 15px;

				.cancel {
					width: 40%;
					text-align: center;
					height: 40px;
					line-height: 40px;
					color: skyblue;
					border: 1px solid skyblue;
					border-radius: 8px;
				}

				.sure {
					width: 40%;
					text-align: center;
					height: 40px;
					line-height: 40px;
					border: 1px solid skyblue;
					background-color: skyblue;
					border-radius: 8px;
					color: #fff;
				}
			}
		}


	}

	.tips {
		font-size: 14px;
		margin-top: 10px;
		padding: 0 20px;
		color: #777;
	}

	.title {
		text-align: right;
		padding: 10px;
		color: #EB655D;
		font-size: 14px;
	}

	.typebox {
		background-color: #fff;
		padding: 10px;

		.type_item {
			display: flex;
			align-items: center;
			padding: 5px 0;
			font-size: 14px;

			text {
				margin-right: 20px;
			}

			radio-group {
				display: flex;
			}

			label {
				display: flex;
				align-items: center;
			}
		}
	}

	.btn {
		margin-top: 15px;

		.btn_sumbit {
			background: #EB655D;
			color: #fff;
			width: 80%;
			font-size: 14px;
			box-sizing: border-box;
		}
	}

	.business {
		margin-top: 10px;
	}

	.inputlist {
		background-color: #fff;
		display: flex;
		font-size: 14px;
		padding: 15px 10px;
		border-bottom: 1px solid #eee;

		.left {
			width: 25%;
			display: flex;

			.hx {
				display: block;
				width: 5px;
				color: red;
				margin-right: 3px;
			}
		}

		.right {
			width: 70%;

			input {
				font-size: 14px;
			}

			.picker_text {
				color: #ccc;
			}

			.inputColor {
				color: #ccc;
			}


		}
	}
</style>
